package org.rui.rpc.enums;

import lombok.Getter;

/**
 * @author: linweirui
 * @date: 2024/12/09 9:10
 */
@Getter
public enum ProtocolMessageStatusEnum {
    /**
     * 请求成功
     */
    OK("ok", 20),
    /**
     * 请求失败
     */
    BAD_REQUEST("badRequest", 40),
    /**
     * 响应失败
     */
    BAD_RESPONSE("badResponse", 50);

    private final String text;
    private final int value;

    ProtocolMessageStatusEnum(String text, int value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据value获取对应枚举类型
     *
     * @param value 枚举对应的值
     * @return
     */
    public static ProtocolMessageStatusEnum getEnumByValue(int value) {
        for (ProtocolMessageStatusEnum protocolMessageStatusEnum : ProtocolMessageStatusEnum.values()) {
            int v = protocolMessageStatusEnum.value;
            if (value == v) {
                return protocolMessageStatusEnum;
            }
        }
        return null;
    }

}
